package com.example.demo;

import com.example.demo.model.DbTypes;
import com.example.demo.model.Student;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA
 * Description
 * User：chenshu
 * Date：2023-12-10
 * Time：17:05
 */
@RestController
public class TestController {
    //用户自定义配置项读取
    @Value("${mykey.key1}")
    private String mykey;

    //读取系统配置项
    @Value("${server.port}")
    private Integer port;

    @Value("${mykey.str1}")
    private String str1;
    @Value("${mykey.str2}")
    private String str2;
    @Value("${mykey.str3}")
    private String str3;

    @Autowired
    private Student student;

    @Autowired
    private DbTypes dbTypes;

    private static Logger log = LoggerFactory.getLogger(TestController.class);

//    @RequestMapping("/hello")
//    public String hello() {
//        return "hello SpringBoot!";
//    }

    @RequestMapping("/hi")
    public String hi() {
        //使用日志对象提供的方法进行日志打印
        log.trace("i am trace");
        log.debug("i am debug");
        log.info("i am info.");
        log.warn("i am warn");
        log.error("i am error");
        return "hi," + mykey + " | " +port;
    }

    @RequestMapping("/myString")
    public String myString() {
        System.out.println("str1:" + str1);
        System.out.println("str2:" + str2);
        System.out.println("str3:" + str3);
        return "test myString";
    }

    @RequestMapping("/student")
    public String SayHi() {
        return "Hi," + student.getName() + " | age:" + student.getAge();
    }

    @RequestMapping("/dbTypes")
    public String DbTypes() {
        return "size:" + dbTypes.getName2().size() + " | get(0):" + dbTypes.getName2().get(0);
    }
}
